/*
 * TcpMediaCasterConnection.h
 *
 *  Created on: 2019年3月1日
 *      Author: terry
 */

#ifndef TCPMEDIACASTERCONNECTION_H_
#define TCPMEDIACASTERCONNECTION_H_

#include "TcpConnection.h"
#include "MediaStream.h"
#include "TByteBuffer.h"
#include "MediaPacketQueue.h"


namespace av
{

class TcpMediaCasterConnection: public TcpConnection ,
                                public av::MediaSink,
                                public std::enable_shared_from_this< TcpMediaCasterConnection >
{
public:
    TcpMediaCasterConnection();
    virtual ~TcpMediaCasterConnection();

    virtual int onOpen();

    virtual void onClose();

    virtual void onWrite(struct bufferevent *bev);

    virtual void onRead(struct bufferevent *bev);

    virtual void onEvent(struct bufferevent *bev, short events);


    virtual void onMediaFormat(const av::MediaFormat& fmt);

    virtual void onMediaPacket(av::MediaPacketPtr& pkt);

    virtual void onMediaEvent(int event);

    void setStreamName(const std::string& name);

protected:

    int writeMedia(av::MediaPacketPtr& pkt);

protected:
    std::string m_peerID;
    std::string m_streamName;
    int m_streamState;

    av::MediaFormat m_format;

    bool    m_jamming;  /// 是否拥塞
    size_t  m_maxCacheSize;

    MediaPacketQueue    m_pktQueue;
    bool    m_empty;

};


} /* namespace av */

#endif /* TCPMEDIACASTERCONNECTION_H_ */
